import React, { Component } from 'react';
import { connect } from 'react-redux'
class Category extends Component {
    render() {
        return (
            <div>
                <p>我是分类页</p>
                <p>store中的count: {this.props.user.count}</p>
                <p><button onClick={this.props.addCount}>count++</button></p>
            </div>
        );
    }
}


function mapStateToProps(state) {
    return {
        user: state.user
    }
}

function mapDispatchToProps(dispatch) {
    return {
        addCount() {
            // 派发修改store中actions任务
            dispatch({ type: '+', payload: 10 })
        },
        jianCount() {
            // 派发修改store中actions任务
            dispatch({ type: '-', payload: 10 })
        }
    }
}

//connect(mapStateToProps,mapDispatchToProps)该函数的调用的结果整体返回一个hoc 强化函数,来处理对应的组件

export default connect(mapStateToProps, mapDispatchToProps)(Category);
